<template>
	<view id="app">
		<view class="mt30 mlr30">
			<!-- 发货 -->
			<view v-if="type == 1">

				<view class="send area plr30 f30">
					<!-- 快递公司 -->
					<view class="rows ptb30">
						<view class="col w200 c999">快递公司</view>
						<view class="col f1 c333">
							<input type="text" v-model="wrap.express_name" placeholder="请填写快递公司" placeholder-class="pls" />
						</view>
					</view>

					<!-- 快递单号 -->
					<view class="rows ptb30 bdt1sE">
						<view class="col w200 c999">快递单号</view>
						<view class="col f1 c333">
							<input type="text" v-model="wrap.express_number" placeholder="请填写快递单号" placeholder-class="pls" />
						</view>
					</view>
				</view>

				<!-- 确定按钮 -->
				<view class="btn pay mt30" @click="send">确定</view>
			</view>

			<!-- 拒绝退款 -->
			<view v-if="type == 2">
				<!-- 退款 -->
				<view class="reject area plr30 f30">
					<!-- 填写理由 -->
					<view class="rows ptb30">
						<view class="col w200 c999">填写理由</view>
						<view class="col f1 c333">
							<input type="text" v-model="wrap.shop_refund_reason" placeholder="请填写退款理由" placeholder-class="pls" />
						</view>
					</view>
				</view>

				<!-- 确定按钮 -->
				<view class="btn pay mt30" @click="reject">确定</view>
			</view>
		</view>

	</view>
</template>
<script>
	// 定义全局变量that
	var that;
	export default {
		// 页面变量
		data() {
			return {
				// 类型 1发货 2拒绝退款
				type: 1,
				// 内容F
				wrap: {},
				// 订单id
				id: '',
			}
		},

		// 页面加载完成后
		onLoad(e) {
			that = this;

			// 订单id
			e.id ? that.id = e.id : '';

			// 类型
			e.type ? that.type = e.type : 1;

			// 设置标题
			var title = '';

			// 判断类型赋值标题
			if (that.type == 1) {
				title = '发货';
			} else if (that.type == 2) {
				title = '拒绝退款';
			}

			// 设置标题文字
			uni.setNavigationBarTitle({
				title: title,
			})
		},

		// 方法集
		methods: {
			// 发货
			send() {
				// 判断必填项
				if (!that.wrap.express_name) {
					// 弹窗提示
					that.alert('请填写快递公司');
					return;
				}
				if (!that.wrap.express_number) {
					// 弹窗提示
					that.alert('请填写快递单号');
					return;
				}

				// 追加id
				that.wrap.id = that.id;
				// 改变状态
				that.wrap.status = 3;

				// 发货时间
				that.wrap.express_time = Date.parse(new Date()) / 1000;

				// 改变订单状态
				that.util.changeOrder({
					data: that.wrap,
					success(rs) {
						// 弹窗提示
						that.alert('操作成功');

						// 半秒后执行
						setTimeout(() => {
							// 返回跳转
							uni.navigateBack();
						}, 500);
					}
				}, that)

			},

			// 拒绝
			reject() {
				// 判断理由是否为空
				if (!that.wrap.shop_refund_reason) {
					// 弹窗提示
					that.alert('请填写拒绝理由');
					return;
				}

				// 改变订单状态
				that.util.changeOrder({
					data: {
						// 订单id
						id: that.id,
						// 退款理由
						shop_refund_reason: that.wrap.shop_refund_reason,
						// 商家反馈
						shop_refund_status: 4,
						// 商家处理时间
						refundtime: Date.parse(new Date())/1000,
					},
					success(rs) {
						// 弹窗提示
						that.alert('操作成功');

						// 半秒后执行
						setTimeout(() => {
							// 返回跳转
							uni.navigateBack();
						}, 500);
					},
				}, that)
			},
		},
	};
</script>
<style>

</style>
